package com.mengxin.secondkill.service.impl;

import com.mengxin.secondkill.mapper.StockMapper;
import com.mengxin.secondkill.message.req.UpdateStockReq;
import com.mengxin.secondkill.message.resp.UpdateStockResp;
import com.mengxin.secondkill.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author mengxin
 * @date 2020/12/29 10:15
 */
public class StockServiceImpl implements StockService {

    @Autowired
    StockMapper stockMapper;

    @Override
    public UpdateStockResp stockUpdate(UpdateStockReq req) {
        UpdateStockResp resp = new UpdateStockResp();
        Long goodsId = req.getGoodsId();
        Long modelId = req.getModelId();
        Long sum = req.getSum();
        //数据库扣减库存
        stockMapper.updateStockSum(goodsId,modelId,sum);
        resp.setMessage("OK");
        return resp;
    }
}
